﻿Imports System.Data.OleDb

Public Class AddPhone
    Inherits System.Web.UI.Page

  

    Protected Sub btn_save_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_save.Click


       

        Dim newFileLoc As String = ""
        If fup_pic.HasFile Then
            newFileLoc = Request.MapPath("pictures")
            newFileLoc = newFileLoc & "/" & fup_pic.FileName
            fup_pic.SaveAs(newFileLoc)
        Else
            Return
        End If


        Dim conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("PhonesConn").ConnectionString)
        Dim sql As String = "INSERT INTO Phones (Brand,Model_Number,Year_Make,Price,Picture,GSM_URL,PostCode,Description,Adding_User) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim cmd As New OleDbCommand(sql, conn)

        conn.Open()
        cmd.Parameters.AddWithValue("@f1", tb_Brand.Text)
        cmd.Parameters.AddWithValue("@f2", tb_ModelName.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Year.Text)
        cmd.Parameters.AddWithValue("@f4", tb_Price.Text)

        cmd.Parameters.AddWithValue("@f5", "Pictures/" & fup_pic.FileName)

        cmd.Parameters.AddWithValue("@f6", tb_URL.Text)
        cmd.Parameters.AddWithValue("@f7", tb_PostCode.Text)
        cmd.Parameters.AddWithValue("@f8", tb_Description.Text)

        cmd.Parameters.AddWithValue("@f9", User.Identity.Name)



       


        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("PhoneList.aspx")


    End Sub
End Class